package com.cirkana.viewer.security.model;

import java.io.DataInputStream;
import java.io.DataOutputStream;

import com.cirkana.serial.SerializablePassData;
import com.cirkana.serial.SerializationException;

public class Credential extends SerializablePassData {

	private String service;
	private String user;

	public String getService() {
		return service;
	}

	public void setService(String service) {
		this.service = service;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	// TODO: Should be protected
	public Credential() {
	}

	@Override
	public void serialize(DataOutputStream out) throws SerializationException {
		serializeString(this.service, out);
		serializeString(this.user, out);
	}

	@Override
	public void deserialize(DataInputStream in) throws SerializationException {
		this.service = deserializeString(in);
		this.user = deserializeString(in);
	}

	@Override
	public String toString() {
		StringBuilder s = new StringBuilder("{");
		s.append("service=");
		if (this.service == null)
			s.append("(null)");
		else
			s.append(this.service);
		s.append(",user=");
		if (this.user == null)
			s.append("(null)");
		else
			s.append(this.user);
		s.append("}");
		return s.toString();
	}

}
